/**
 * @author qiuxj
 * @text 套餐管理
 */
var combo = {
    init: function(){
        // 定义DWR
        var dwr = {
            createComdo: comboDwr.createComdo,
            updateComdo: comboDwr.updateComdo,
            getCombo: comboDwr.getCombo,
            getStaticValueKls: staticDwr.getStaticValueKls,
            pageCombo: comboDwr.pageCombo
        };
        
        // 增加按钮
        var addBtn = new CQCIS.Button({
            text: '添加 (<u>A</u>)',
            iconCls: 'btn_insert',
            handler: function(){
            		comboWin.show();
            }
        });
        
        // 修改按钮
        var editBtn = new CQCIS.Button({
            text: '修改 (<u>E</u>)',
            iconCls: 'btn_modify',
            handler: function(){
                if (grid.getSelectedRow()) {
                    comboWin.load(grid.getSelectedRow()['comboId']);
                } else {
                    CQCIS.msg("请选择要修改的套餐信息！");
                }
            }
        });
        
        // 添加信息表单字段
        var comboFormMeta = [{
            id: 'comboId',
            desc: '套餐ID',
            field: 'comboId',
            type: 'int',
            xtype: 'hidden'
        }, {
            field: 'comboName',
            desc: '套餐名称'
        }, {
            field: 'comboDesc',
            desc: '套餐描述',
            xtype: 'htmleditor'
        }, {
            field: 'prodType',
            desc: '所属类型',
            type: 'int',
            xtype: 'rcombo',
            obj: {
                ds: {
                	params: {
        				state: 1,
        				staticTypeId: 10000
        			},
                    call: dwr.getStaticValueKls,
                    fields: ['key', 'label']
                },
                emptyText: '请选择套餐',
                allowBlank: false
            },
            width: 80
        }, {
            field: 'upComboId',
            desc: '上级套餐ID',
            type: 'int',
            xtype: 'hidden',
            obj: {
            	value: '0'
            }
        }, {
            field: 'isBottom',
            desc: '是否是底层',
            type: 'int',
            xtype: 'hidden',
            obj: {
            	value: '1'
            }
        }, {
            field: 'state',
            desc: '状态',
            type: 'int',
            xtype: 'acombo',
            obj: {
                ds: {
                    data: [[0, '失效'], [1, '有效']],
                    fields: ['key', 'label']
                },
                value: 1
            }
        }, {
            field: 'attr',
            desc: '属性串',
            obj: {
            	value: '0000000000'
            }
        }];
        
        // 列表数据对象
        var comboPageMeta = [{
            id: 'comboId',
            desc: '套餐ID',
            field: 'comboId',
            type: 'int',
            hidden: true
        }, {
            desc: '套餐名称',
            field: 'comboName'
        }, {
            desc: '套餐描述',
            field: 'comboDesc'
        }, {
            field: 'state',
            desc: '状态',
            renderer: function(val){
                var str;
                switch (val) {
                	case '0':
                		str = '失效';
                    	break;
                    case '1':
                        str = '有效';
                        break;
                    default:
                        str = '';
                        break;
                }
                return str;
            }
        }, {
            field: 'attr',
            desc: '属性串'
        }];
        
         // 定义表单
        var comboForm = new CQCIS.form.DWRForm({
            dwr: {
                load: dwr.getCombo,
                save: dwr.createComdo,
                update: dwr.updateComdo
            },
            metas: comboFormMeta,
            listeners: {
                'saveafter': function(){
                    CQCIS.msg('套餐信息保存成功！');
                    grid.reload();
                }
            }
        });
        
        // 定义窗口
        var comboWin = new CQCIS.form.WinForm({
            title: '添加套餐信息',
            width: 660,
            height: 380,
            items: comboForm
        });
        
        // 片区信息grid
        var grid = new CQCIS.grid.PageGrid({
            firstColumn: 'radio',
            dwr: {
                call: dwr.pageCombo
            },
            filter: {},
            sortable: true,
            metas: comboPageMeta,
            tbar: ['-', addBtn, '-', editBtn],
            bbar: true,
            initload: true,
            listeners: {
                'rowdblclick': editBtn.handler,
                'rowcontextmenu': function(o, rowIndex, e){
                    e.stopEvent();
                    //定义增加右键菜单
                    var addMenu = new Ext.menu.Item({
                        iconCls: 'menu_insert',
                        id: 'addMenu',
                        text: '增加',
                        handler: addBtn.handler
                    });
                    //定义修改右键菜单
                    var editMenu = new Ext.menu.Item({
                        iconCls: 'menu_modify',
                        id: 'editMenu',
                        text: '修改',
                        handler: editBtn.handler
                    });
                    //定义列表右键菜单
                    var gridMenu = new Ext.menu.Menu({
                        id: 'gridMenu',
                        items: [addMenu, editMenu]
                    });
                    gridMenu.showAt(e.getXY());
                }
            }
        });
        grid.render();
    }
};

Ext.onReady(combo.init, combo);
